package composite.general;

/**
 * @Author：LJ
 * @Description：
 * @Date: 2017/12/1
 * @Modified By:
 */
public class Client {
    public static void main(String[] args) {
        Composite root = new Composite();
        Composite sub = new Composite();
        Leaf leaf = new Leaf();
        root.doSomething();
        root.add(sub);
        sub.add(leaf);
    }

    public static void display(Composite root) {
        for (Component c : root.getChildren()) {
            if (c instanceof Leaf) {
                c.doSomething();
            } else {
                display((Composite) c);
            }
        }
    }
}
